package com.kaifamiao.N0725;

import java.util.Random;
import java.util.Scanner;

public class Person {
    public String name;

    public char gender;

    public int age;

    public boolean isMarry; // 是否已婚

    //想法：先判断是否符合结婚条件
    public boolean canMarry(Person person){
        if(this.gender == '女' && this.gender != person.gender && this.age >= 20 && person.age >= 22 && !this.isMarry && !person.isMarry){
            return true;
        }else if(this.gender == '男' && this.gender != person.gender && this.age >= 22 && person.age >= 20 && !this.isMarry && !person.isMarry){
            return true;
        }else{
            return false;
        }
    }
    //随机性别的实现
    public char getGender(){
        char gender[] = {'男','女'};
        Random r = new Random();
        int n = r.nextInt(2);//生成【0，2）区间里面的整数
        return gender[n];
    }
    //再来个随机年龄吧
    public int getAge(){
        Random r = new Random();
        int nn = r.nextInt(10,40);
        return nn;
    }
        public static void main(String[] args) {
            Person me = new Person();
            // 自己的属性
            me.name = "梁全年";
            me.age = me.getAge();
            me.gender = me.getGender();
            me.isMarry = false;
            Person obj = new Person();
            // 对象的属性
            obj.name = "安全";
            obj.gender = obj.getGender();
            obj.isMarry = false;
            obj.age = obj.getAge();

            System.out.println("对象的性别是:" + obj.getGender()+"\t"+ "对象的年龄是:" + obj.getAge());

            System.out.println("我的性别是" + me.getGender()+ "\t"+"年龄：" + me.getAge());

            if (me.canMarry(obj)){
                System.out.println(me.name + "能和" + obj.name + "结婚，恭喜");
            } else {
                System.out.println(me.name + "不能和" + obj.name + "结婚, 请注意！！");
            }

        }

    }

